﻿@model $prjsn$.Common.Models.Services.IArticleModel

@this.CreateForm()
@{
    var files = new Fieldset("w49p mh150", "UploadAttachments");
    for(var i = 1; i <= 5; i++)
    {
        files.AddControls(new DL
        {
            new DT {new Literal("file " + i)},
            new DD {new Input(InputType.File).SetName("NewFile" + i)},
        });
    }

    // I. Pictures
    var attachments = new PlaceHolder();
    foreach (var file in Model.Attachments.Where(f => f.ContentType.IsImage))
    {
        attachments.AddControls(new DL
        {
            new DT
            {
                new Input(InputType.Text, "w400")
                    .SetValue("[IMG:"+ file.RelativePath +"]")
            },
            new DD("h100")
            {
                new Image(ResourceManager.CreateUrl(file.RelativePath),"h100")
                    .SetAlt(file.RelativePath)
            },
            new DD
            {
                new Anchor()
                    .SetHref(Url.Action("DeleteFile", new { id = Model.Item.ID, fileName = file.Name }))
                    .AddControls(new Literal("DeleteFile", true))
            }
        });
    }
    // II. Images
    foreach (var file in Model.Attachments.Where(f => f.ContentType.IsZip))
    {
        attachments.AddControls(new DL
        {
            new DT
            {
                new Input(InputType.Text, "w400")
                    .SetValue("[URL:" + file.RelativePath + "|TEXT:" + file.Name + "]")
            },
            new DD("h100")
            {
                new Image(ResourceManager.CreateUrl(file.RelativePath),"h100")
                    .SetAlt(file.RelativePath)
            },
            new DD
            {
                new Anchor()
                    .SetHref(Url.Action("DeleteFile", new { id = Model.Item.ID, fileName = file.Name }))
                    .AddControls(new Literal("DeleteFile", true))
            }
        });
    }
}
@AddControls(
    new Div("w99p")
    {
        files,
        new Fieldset("w48p", "Attached") { attachments },
    })
@this.CloseForm()